package cn.nexd.app.collector.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.nexd.app.collector.R;
import cn.nexd.app.collector.model.Mall;
import cn.nexd.app.collector.widget.OnRecyclerViewItemClickListener;


/**
 * Created by xun on 2016/8/10.
 */
public class MallAdapter extends RecyclerView.Adapter<StringViewHolder> {

    private List<Mall> malls;
    private OnRecyclerViewItemClickListener itemClickListener;

    public MallAdapter() {
        this.malls = new ArrayList<>();
    }

    public void setMalls(List<Mall> malls) {
        this.malls.clear();
        this.malls.addAll(malls);
        notifyDataSetChanged();
    }

    public List<Mall> getMalls() {
        return malls;
    }

    public void setItemClickListener(OnRecyclerViewItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    @Override
    public StringViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_item_building, parent, false);
        return new StringViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final StringViewHolder holder, final int position) {
        holder.textView.setText(malls.get(position).getCnName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemClickListener.onClick(position, holder);
            }
        });

    }

    @Override
    public int getItemCount() {
        return malls.size();
    }
}
